package com.notary.tx_live_plugin.platform;

import android.content.Context;

import androidx.annotation.NonNull;

import com.notary.tx_live_plugin.FlavorConfigImpl;
import com.notary.tx_live_plugin.util.TxConstant;

import java.lang.ref.WeakReference;
import java.util.HashMap;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;

/**
 * 当前plugin的MethodCallHandler
 */
public class PluginMethodCallHandlerImpl implements MethodChannel.MethodCallHandler {

    WeakReference<Context> mContextWeak;

    public PluginMethodCallHandlerImpl(Context context){
        mContextWeak = new WeakReference<>(context);
    }

    @Override
    public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
        ///初始化
        if(call.method.equals(TxConstant.PluginMethod.init)){
            //如果是专业版，txLive，需要传递参数
            boolean can = FlavorConfigImpl.getInstance().initApplication(mContextWeak.get(),
                    (HashMap<String, Object>) call.arguments);
            result.success(can);
        } else if (call.method.equals(TxConstant.PluginMethod.getPlatformVersion)) {
            result.success("Android " + android.os.Build.VERSION.RELEASE);
        } else {
            result.notImplemented();
        }
    }
}
